<list_name>=list(iterable)
myset={5,2,1,7} lst=list(myset) print(lst)
[5, 2, 1, 7]
vowelString = 'AEIOU' lst=list(vowelString) print(lst)
lst=[10,20,50,30] lst.append(40) print(lst) >>> [10, 20, 50, 30, 40] |
lst=[10,20,50,30] lst.clear() print(lst) >>> [] |
lst1=[10,20,50,30] lst2=lst.copy() print(lst2) >>> [10,20,50,30] |
lst=[ 10,20,50,30,50,10,50] print(lst.count(50)) >>> 3 |
lst1 = ['ram', 'shyam', 'gopal'] lst2 = ['seeta', 'geeta'] lst1.extend(lst2) print(lst1) >>>['ram','shyam','gopal','seeta','geeta'] |
lst1 = ['ram', 'shyam', 'gopal'] print(lst1.index('gopal')) >>> 2 |
fruits = ['apple', 'banana', 'cherry'] fruits.insert(1, "orange") print(fruits) >>> ['apple','orange', 'banana', 'cherry'] |
fruits = ['apple', 'banana', 'cherry'] fruits.pop(1) print(fruits) >>> ['apple', 'cherry'] |
fruits = ['apple', 'banana', 'cherry'] fruits.remove('banana') print(fruits) >>> ['apple', 'cherry'] |
fruits = ['apple', 'banana', 'cherry'] fruits.reverse( ) print(fruits) >>> ['cherry', 'banana', 'apple' ] |
fruits = [ 'banana', 'cherry', 'apple'] fruits.sort() print(fruits) >>> ['apple', 'banana', 'cherry'] |
lst=[4,5,1,3,8,12,75,23,116,25,7] elst=[] olst=[] for n in lst: if n%2==0: elst.append(n) else: olst.append(n) print("Even list :",elst) print("Odd list :",olst)
Even list: [4, 8, 12, 116] Odd list: [5,1,3,75,23,25,7]
lst=[4,5,2,4,7,5,2] nlst=[] for n in lst: if nlst.count(n)==0: nlst.append(n) print("original list is",lst) print("new list is",nlst)
original list is [4, 5, 2, 4, 7, 5, 2] new list is [4, 5, 7, 2]